package jdbc;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * 根据给定的用户名删除指定用户
 */
public class Test2 {
    public static void main(String[] args) {
        UserInfo userinfo = InputUtil.getInputObject(new UserInfo(),"删除用户" , "删除");
        System.out.println(userinfo);
    try (Connection connection = DBUtil.getConnection()
    ){
      String sql = "DELETE FROM userinfo WHERE username = ? AND password = ? ";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setString(1, userinfo.getUsername());
        ps.setString(2, userinfo.getPassword());

        int num = ps.executeUpdate();
                if (num >0){
                    System.out.println("删除成功");
                }else{
                    System.out.println("删除失败");
                }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    }
}